package com.yufuchang;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yufuchang on 2020/8/12.
 */
@ControllerAdvice
public class GlobalConfig {

    @ModelAttribute(value = "msg")
    public String getMessage(){
        return "欢迎学习springboot";
    }

    @ModelAttribute(value = "map")
    public Map<String,String> getMapInfo(){
        HashMap hashMap = new HashMap();
        hashMap.put("name","yufuchang1111111");
        hashMap.put("age","300");
        return hashMap;
    }

    @ModelAttribute
    public void getModel(Model model){
        model.addAttribute("msg2", "欢迎学习SpringBoot");
        HashMap<String, String> map = new HashMap<>();
        map.put("name", "yufuchang");
        map.put("age", "200");
        model.addAttribute("map2", map);
    }
}
